package com.xiaobai.common;

import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author: 小白白
 * @create: 2022-01-06
 **/

@Slf4j
public enum  AddressEnum {

    CUSTOM("自定义", null, 0),
    GUANHUA("光华", "广东省茂名市茂南区光华北路广东石油化工学院光华校区", 1),
    GUANDU("官渡", "广东省茂名市茂南区官渡二路广东石油化工学院官渡校区", 2),
    XICHENG("西城", "广东省茂名市茂南区公馆镇科创路广东石油化工学院西城校区", 3),
    ;

    private String desc;
    private String address;
    private Integer index;

    AddressEnum(String desc, String address, Integer index) {
        this.desc = desc;
        this.address = address;
        this.index = index;
    }

    public static String getAddress(Integer index, String defaultAddress) {
        if (defaultAddress == null) {
            defaultAddress = GUANDU.address;
        }
        if (index.equals(CUSTOM.index)) {
            return defaultAddress;
        }
        for (AddressEnum addressEnum : AddressEnum.values()) {
            if (addressEnum.index.equals(index)) {
                return addressEnum.address;
            }
        }
        log.error("未定义的addressIndex");
        return defaultAddress;
    }

}
